package com.ukao.cashregister.pesenter;

import android.content.Context;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.BaseBean;
import com.ukao.cashregister.bean.BatchlTabBean;
import com.ukao.cashregister.bean.FactoryBatchBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.view.FactoryBatchView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/26.
 */

public class FactoryBatchPesenter extends BasePresenter<FactoryBatchView> {

    public FactoryBatchPesenter(FactoryBatchView view) {
        attachView(view);
    }


    /**
     * 请求袋号
     */
    public void    requestBagNumber(Context  mContext,String  status,String bagCode){
        HashMap mHashMap=new HashMap<String,String>();
        if (!status.isEmpty()){
            mHashMap.put("status",status) ;
        }
        mHashMap.put("code",bagCode);
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.orderProductBatchIn(Constant.createParameter(mHashMap)),
                new ApiCallback<BatchlTabBean>() {
                    @Override
                    public void onSuccess(BatchlTabBean model) {
                        if (model.getHttpCode() == 200) {
                            mvpView.receiveBagNumberData(model.getData().getList());
                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }

                    @Override
                    public void onFinish() {
                        mvpView.finishLoad();
                    }
                });
    }


    /**
     *  送厂tab 列表
     * @param mContext
     * @param status
     */
    public void orderProductBatchIn(Context  mContext,String  status,int pageNum,int  pageSize) {
        HashMap mHashMap=new HashMap<String,String>();
        if (!status.isEmpty()){
            mHashMap.put("status",status) ;
        }
        mHashMap.put("pageNum",pageNum+"");
        mHashMap.put("pageSize",pageSize+"");
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.orderProductBatchIn(Constant.createParameter(mHashMap)),
                new ApiCallback<BatchlTabBean>() {
                    @Override
                    public void onSuccess(BatchlTabBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.loadSuccess(model.getData().getList(), model.getData().getPages());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }




                    @Override
                    public void onFinish() {
                    mvpView.finishLoad();
                    }
                });
    }

    /**
     *   送厂完成

     */
    public void orderProductComplete( Context mContext,String id ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("id",id);
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.orderProductcomplete(Constant.createParameter(mHashMap)),
                new ApiCallback<FactoryBatchBean>() {
                    @Override
                    public void onSuccess(FactoryBatchBean model) {
                        if (model.getHttpCode() == 200) {

                            mvpView.loadFinishSuccess("完成成功");

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }


                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    /**
     * 批次 删除

     */
    public void batchIndelete( Context mContext,String id) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("id",id);
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.batchIndelete(Constant.createParameter(mHashMap)),
                new ApiCallback<BaseBean>() {
                    @Override
                    public void onSuccess(BaseBean model) {
                        if (model.getHttpCode() == 200) {

                            mvpView.deleteSuccess("删除成功");

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }


                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }




}
